package guowei.guliorder.order.web;

import guowei.guliorder.order.config.AlipayTemplate;
import guowei.guliorder.order.service.OrderService;
import guowei.guliorder.order.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class OrderPayWeb {

    @Autowired
    AlipayTemplate alipayTemplate;

    @Autowired
    OrderService orderService;

    //支付宝支付     响应的是一个页面，而非json格式字符串    告诉浏览器端，产生的是一个html
    @ResponseBody
    @GetMapping(value = "/payOrder",produces = "text/html")
    public String payAliPay(@RequestParam("orderSn") String orderSn){

        PayVo payVo1 = orderService.getPayVoByOrderSn(orderSn);
        String pay = null;
        try {       //尝试支付宝支付
            pay = alipayTemplate.pay(payVo1);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return pay;
    }
}